package concurrent;

import com.google.common.base.Function;
import com.google.common.collect.Maps;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutionException;

/**
 * TODO: please加入描述
 * @author chenxin
 * @time 2017-05-06-20:27
 */
public class HashMapKeyTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Map<AbsFoo, Integer> map = new HashMap<>();
        MyObject a = new MyObject("a", 1);
        MyObject b = new MyObject("b", 2);
        map.put(a, 1);
        map.put(b, 2);
        Integer v = map.get(a);
        System.out.println(v);
    }

    static abstract class AbsFoo {

    }

    static class MyObject extends AbsFoo {
        private String str;

        private int foo;

        public MyObject(String str, int foo) {
            this.str = str;
            this.foo = foo;
        }

        public int getFoo() {
            return foo;
        }

        public void setFoo(int foo) {
            this.foo = foo;
        }

        public String getStr() {
            return str;
        }

        public void setStr(String str) {
            this.str = str;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            MyObject myObject = (MyObject) o;
            return foo == myObject.foo &&
                    Objects.equals(str, myObject.str);
        }

        @Override
        public int hashCode() {
            return Objects.hash(str, foo);
        }

        @Override
        public String toString() {
            return "MyObject{" +
                    "str:'" + str + '\'' +
                    ", foo:" + foo +
                    '}';
        }
    }
}
